//
//  SafeTimer.m
//  JadeShop
//
//  Created by mac on 2019/8/2.
//  Copyright © 2019 SZJ.test. All rights reserved.
//

#import "SafeTimer.h"

@implementation SafeTimer

+(void)beginWithTime:(NSInteger)time withCallBack:(void(^)(void))callBack{
    dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));
    dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, DISPATCH_TIME_NOW * NSEC_PER_SEC, time * NSEC_PER_SEC);
    dispatch_source_set_event_handler(timer, ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            callBack();
        });
    });
    dispatch_resume(timer);
}

@end
